const http = require('http');
const url = require('url')

const server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {
    'Content-Type': 'text/plain;charset=utf-8'//状态码+响应头属性
  });

  // 解析URL参数
  //parse将字符串转成对象,req.url="/?url=123&name=321"，
  //true表示params是{ url: "123", name: "321" } ，false表示params是url = 123 & name=321
  var params = url.parse(req.url, true).query
  res.write('网站名:' + params.name)
  
  res.write('网站url:' + params.url)
  res.end();
})

server.listen(3000, function () {
  console.log('server running at http://127.0.0.1:3000')
})


